package com.example.blog.controller;

import com.example.blog.common.Result;
import com.example.blog.util.JwtTokenUtil;
import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ganggang
 * @version 1.0
 * @date 2022/2/11 9:45 上午
 */
@RestController
public class TokenController {

    @GetMapping("/token")
    public Result token(@RequestParam("token") String token,
                        @RequestParam("access_token") String access_token){
        JwtTokenUtil jwtTokenUtil = new JwtTokenUtil();
        String usernameFromToken = jwtTokenUtil.getUsernameFromToken(access_token);
        Map<String,Object> map = new HashMap<>();
        map.put("username",usernameFromToken);

        Map<String,String> tokenMap = new HashMap<>();
        tokenMap.put("token",jwtTokenUtil.doGenerateToken(map,"ganggang"));
        tokenMap.put("access_token",jwtTokenUtil.doGenerateTokenRefresh(map,"ganggang"));
        return Result.succ(tokenMap);
    }
}
